<?php
//活动领取人查询条件

namespace App\Repositories\Filter;

class ActivityReceiversFilter
{

    /**
     * 处理查询条件
     * @param $query
     * @return array[]
     */
    public static function handleQuery($query = []) {
        $where = [];
        $whereIn = [];
        if(!empty($query['id'])) {
            $where[] = ['id', $query['id']];
        }
        if(!empty($query['ids'])) {
            $whereIn[] = ['id', $query['ids']];
        }
        if(!empty($query['name_keyword'])) {
            $where[] = ['name', 'like', "%{$query['name_keyword']}%"];
        }
        if(!empty($query['mobile'])) {
            $where[] = ['mobile', $query['mobile']];
        }
        if(!empty($query['id_number'])) {
            $where[] = ['id_number', $query['id_number']];
        }
        if(!empty($query['id_numbers'])) {
            $whereIn[] = ['id_number', $query['id_numbers']];
        }
        if(!empty($query['receive_date_lt'])) {
            $where[] = ['receive_date', '<', $query['receive_date_lt']];
        }
        if(!empty($query['real_id'])) {
            $where[] = ['real_id', $query['real_id']];
        }
        if(!empty($query['real_ids'])) {
            $whereIn[] = ['real_id', $query['real_ids']];
        }
        if(!empty($query['openid'])) {
            $where[] = ['openid', $query['openid']];
        }
        if(!empty($query['openids'])) {
            $whereIn[] = ['openid', $query['openids']];
        }
        if(!empty($query['activity_id'])) {
            $where[] = ['activity_id', $query['activity_id']];
        }
        if(!empty($query['activity_ids'])) {
            $whereIn[] = ['activity_id', $query['activity_ids']];
        }
        //性别
        if(!empty($query['gender'])) {
            $where[] = ['gender', $query['gender']];
        }
        if(!empty($query['birthday_gte'])) {
            $where[] = ['birthday', '>=', $query['birthday_gte']];
        }
        if(!empty($query['birthday_lt'])) {
            $where[] = ['birthday', '<', $query['birthday_lt']];
        }
        //是否有资格领取： 1有资格，2没资格
        if(!empty($query['receiver_status'])) {
            $where[] = ['receiver_status', $query['receiver_status']];
        }
        //1:已认证、2:未认证；
        if(!empty($query['auth_status'])) {
            $where[] = ['auth_status', $query['auth_status']];
        }
        //使用方式：1为代金券，2为二维码（只能使用一种，已最后一次认证为准）
        if(!empty($query['type'])) {
            $where[] = ['type', $query['type']];
        }
        if(!empty($query['auth_end_date_lt'])) {
            $where[] = ['auth_end_date', '<', $query['auth_end_date_lt']];
        }
        if(!empty($query['auth_end_date_gt'])) {
            $where[] = ['auth_end_date', '>', $query['auth_end_date_gt']];
        }
        if(!empty($query['auth_start_date_lte'])) {
            $where[] = ['auth_start_date', '<=', $query['auth_start_date_lte']];
        }
        if(!empty($query['auth_start_date_gte'])) {
            $where[] = ['auth_start_date', '>=', $query['auth_start_date_gte']];
        }


        return [
            'where' => $where,
            'whereIn' => $whereIn,

        ];
    }

}
